class Solution {
public:
    vector<vector<int>> graph;
    vector<bool> vis;
    bool bfs(int root, int dest)
    {
        queue<int> q;
        q.push(root);
        while(!q.empty())
        {
            auto u=q.front(); q.pop();
            if(vis[u]) continue;
            vis[u]=true;
            for(auto v:graph[u])
            {
                if(v==dest) return true;
                q.push(v);
            }
        }
        return false;
    }
    bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {
        if(source==destination) return true;
        graph.resize(n);
        vis.resize(n, false);

        for(auto &edge:edges)
        {
            int u=edge[0], v=edge[1];
            graph[u].emplace_back(v);
            graph[v].emplace_back(u);
        }
        // for(auto v:graph[source])
        //     if(v==destination) return true;
        // return false;
        return bfs(source, destination);
    }
};